function passwordHandler(player, oldpassword, newpassword)
	local account = getPlayerAccount(player)
	if (account) then
		if (isGuestAccount(account)) then
			outputChatBox("You must be logged in to change your password.", player)
			return
		end
		local playerName = getPlayerName(player)
		local password_check = getAccount(playerName, oldpassword)
		if (password_check ~= false) then
			if (string.len(newpassword) >= 5) then
				setAccountPassword(account, newpassword)
				triggerClientEvent(player, "hidePasswordWindow", getRootElement())
				outputChatBox("Password changed succesfully!", player)
			else
				outputChatBox("Your new password must be at least 5 characters long!", player)
			end
		else
			outputChatBox("Old password invalid.", player)
		end
	end
end

function loginHandler(player, username, password)
	local account = getAccount(username, password)
	if (account ~= false) then
		if (logIn(player, account, password) == true) then
			triggerClientEvent (player, "hideLoginWindow", getRootElement())
		else
			triggerClientEvent (player, "unknownError", getRootElement())
		end
	else
		triggerClientEvent (player, "loginWrong", getRootElement())
	end
end

function registerHandler(player, username, password)
	local account = getAccount(username, password)
	if (account ~= false) then
		triggerClientEvent(player, "registerTaken", getRootElement())
	else
		account = addAccount(username, password)
		if (logIn(player, account, password) == true) then
			triggerClientEvent(player, "hideLoginWindow", getRootElement())
		else
			triggerClientEvent(player, "unknownError", getRootElement())
		end
	end
end

function showBackgroundMovie()
	-- Look at City Hall
	fadeCamera (source, true, 2.5)
	setCameraMatrix (source, 1435.30, -1700.45, 13.55, 1494.44, -1772.31, 18.80, 0, 180)
	setTimer (setCameraMatrix, 10000, 1, source, 1512.85, -1628.98, 14.05, 1554.70, -1679.20, 16.20, 0, 180)
	setTimer (setCameraMatrix, 20000, 1, source, 1234.57, -1332.70, 14.07, 1172.29, -1323.15, 15.40, 0, 180)
	setTimer (setCameraMatrix, 30000, 1, source, 1435.30, -1700.45, 13.55, 1494.44, -1772.31, 18.80, 0, 180)
end

addEvent("submitChangepw", true)
addEvent("submitLogin", true)
addEvent("submitRegister", true)
addEventHandler("submitChangepw", root, passwordHandler)
addEventHandler("submitLogin", root, loginHandler)
addEventHandler("submitRegister", root, registerHandler)
-- addEventHandler("onPlayerJoin", getRootElement(), showBackgroundMovie)